package Objects;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.util.Log;

import com.InfinityRun.Assets;
import com.InfinityRun.GameScene;
import com.InfinityRun.MainGame;

public class ObstacleManager
{
	public List<Obstacle> obs;
	Random random;
	int r;
	float count;
	Bitmap objImage;
	
	public ObstacleManager()
	{
		obs = new ArrayList<Obstacle>();
		count = 0;
		random = new Random();
		objImage = Assets.obstacle;
	}
	public void random()
	{
		Obstacle obj;
		count = 0;
		r = random.nextInt(20) % 2 ;
		float posX = 0;

		switch(r)
		{
			case 0:
				posX = random.nextFloat() * MainGame.getWidth() * 0.5f;
				break;
			case 1:
				posX = random.nextFloat() * 2 *(MainGame.getWidth() * 0.5f - objImage.getWidth() * 0.5f);
				break;
				
			default:
				break;

		}
		obj = new Obstacle(Assets.obstacle.getWidth(),Assets.obstacle.getHeight(),0,100,objImage);				
		obj.position.x = posX;
		obs.add(obj);
	}
	public void update(float deltaTime)
	{
		count += deltaTime;
		
		if(count > 3)
		{
			random();
		}
		for(Obstacle o: obs)
		{
			o.Update(deltaTime);
		}
		remove();
	}
	public void draw(Canvas c)
	{
		for(Obstacle o : obs)
		{
			o.Draw(c);
		}
	}
	
	public void remove()
	{
		if(obs != null)
		for(Obstacle o : obs)
		{
			if(o.position.x + o.bounds.width < 0)
			{
				obs.remove(o);
				break;
			}
		}
	}
	//public Obstacle getObstacle(){return obj;}
}
